<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class Category extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'group' => Group::collection($this->whenLoaded('group')),
            'created_at' => $this->created_at?$this->created_at->toDateTimeString():'',
            'updated_at' => $this->updated_at?$this->updated_at->toDateTimeString():'',
        ];
        return parent::toArray($request);
    }
}
